/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: javase2203 - GuessNumber
 * <p>Powered by webrx On 2022-07-14 16:12:49
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class GuessNumber {
    public static void main(String[] args) {
        //随机出题
        Random rand = new Random();

        int level  = rand.nextInt(1,11);//10级
        int a = 1;
        int b = level*50;

        int num = rand.nextInt(a,b+1);

        int n = 0;

        //接收键盘输入
        Scanner sc = new Scanner(System.in);
        while(true){
            ++n;
            System.out.printf("请输入[%d-%d]：",a,b);
            int t = sc.nextInt();
            if(t<a || t>b){
                System.out.printf("请重新%n");
                --n;
                continue;
            }
            if(t>num){
                System.out.printf("%d、太大了。%n",n);
            }else if(t<num){
                System.out.printf("%d、太小了。%n",n);
            }else{
                System.out.printf("%d、恭喜，猜对了(%d分)。%n",n,(110 - n*10 ));
                break;
            }
            if(n>=10){
                System.out.print("游戏结束");
                break;
            }
        }

    }
}
